﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ecopsy.DataTier;
using System.Xml;

namespace AgencyEntityLib.BaseEntity
{
    /// <summary>
    /// Сторона носителя
    /// </summary>
    public class Side : EntitySingle
    {
        private string _Litera= string .Empty ;
        public string Litera { get { return _Litera; } set { _Litera = value; } }

        private decimal  _GRP = 0;
        public decimal GRP { get { return _GRP; } set { _GRP = value; } }

        private decimal  _OTS = 0;
        public decimal OTS { get { return _OTS; } set { _OTS = value; } }

                
        private string _Direction = string.Empty;
        public string Direction { get { return _Direction; } set { _Direction = value; } }

        private string _LookDistance = string.Empty;
        public string LookDistance { get { return _LookDistance; } set { _LookDistance = value; } }

        private int _SurfaceCount= 1;
        public int SurfaceCount { get { return _SurfaceCount; } set { _SurfaceCount = value; } }
        
        private PriceList _PriceList = new PriceList();
        public PriceList PriceList { get { return _PriceList; } set { _PriceList = value; } }



        public int CurrentPrice
        { 
        get{    return _PriceList.GetCurrentPrice(); }
            set { ;}
        }


        /// <summary>
        /// Загрузка объекта Side  
        /// </summary>
        public void LoadReadOnly()
        {
            //tls.ReadXml("SideLoad", this);
            SecuretyContext SC = AppContext.GetSC();
            try
            {   
                SqlTools tls = new SqlTools(SC);
                XmlReader r = tls.ReadXml("SideLoad", this);
                XmlDocument d = new XmlDocument();
                d.Load(r);
                this.ReadXml(d.FirstChild);

                base.Load();
            }
            finally
            {
                if (SC.Connection.State == System.Data.ConnectionState.Open) SC.Connection.Close();
            }
            

        }



        /// <summary>
        /// Тип конструкции как текст
        /// </summary>
        public  string GetFullDescribe()
        {
            return (this.GRP.ToString());
        }

        /// <summary>
        /// Возвращает сумму на текущую дату, с учетом скидок
        /// </summary>
        /// <param name="PriceDate"></param>
        /// <returns></returns>
        public  int GetPrice( DateTime PriceDate)
        {
            return PriceList.GetCurrentPriceForDate(PriceDate);

        }


        
    }
}
